package com.yequan.spring.bean.definition;

import com.yequan.spring.ioc.overview.domain.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * bean实例化
 *
 * @author : Administrator
 * @date : 2020/4/3
 */
public class BeanInstantiationDemo {


    public static void main(String[] args) {

        //创建 BeanFactory 容器
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-instantiation-context.xml");

        User userByStaticMethod = applicationContext.getBean("user-by-static-method", User.class);
        User userByInstanceMethod = applicationContext.getBean("user-by-instance-method", User.class);
        User userByFactoryBean = applicationContext.getBean("user-by-factory-bean", User.class);
        System.out.println("静态方法实例化: " + userByStaticMethod);
        System.out.println("实例方法实例: " + userByInstanceMethod);
        System.out.println("FactoryBean实例: " + userByFactoryBean);
        System.out.println(userByStaticMethod == userByInstanceMethod);
        System.out.println(userByStaticMethod == userByFactoryBean);

    }

}
